#pragma once
#include "../../DataStructsDef.h"
#include "..\\UtilDefs.h"
#include "..\\..\\Effects11\\Inc\\d3dx11effect.h"
#include "..\\DirectoryUtil.h"
#include "..\\..\\IO\\Material.h"
#include "RenderableTexture2D.hpp"
class CD3DUtilityFunction
{
public:
	CD3DUtilityFunction(void);
	~CD3DUtilityFunction(void);
	static HRESULT CompileShaderFromFile( WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut );	
	static HRESULT FillVec3(float x, float y, float z, D3DXVECTOR3* pDst);
	static HRESULT CreateVBVec3(ID3D11Device* pd3dDevice, int iDataWidth, int iDataHeight, float fWidthLength, float fHeightLength, 
		                        float fStartOffsetX, float fStartOffsetY, float* pSrcDataBuf, ID3D11Buffer** ppVB);
	static HRESULT CreateIBGrid32Bit(ID3D11Device* pd3dDevice, int iDataWidth, int iDataHeight, ID3D11Buffer** ppIB);
	static HRESULT CreateVertexBuffer(ID3D11Device* pd3dDevice, int iStride, float* pSrcDataBuf, int iNumVertices, ID3D11Buffer** ppVB);
	static HRESULT CreateIndexBuffer(ID3D11Device* pd3dDevice, int iNumofIndices, void* pIndicesBuf, ID3D11Buffer** ppIB, bool b32Bit = true);
	static HRESULT CreateEffectsFromFile(ID3D11Device* pd3dDevice, WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DX11Effect** ppEffect );
	static HRESULT CreateVertexLayout(ID3D11Device* pd3dDevice, const D3D11_INPUT_ELEMENT_DESC layout[], int numElems, ID3DX11EffectTechnique* pTech, ID3D11InputLayout** ppLayout11);
	static D3DXMATRIX LerpMatrix(D3DXMATRIX& a, D3DXMATRIX& b, float s);
	static void CreateFileName(char pFileName[], unsigned int iSize, CDirectoryUtil* pDirUtil, enum SUBDIRECTORY iSubFolder, TCHAR* sFileName);
	static HRESULT CreateD3D9Device(IDirect3DDevice9** ppd3dDevice);
	static void InitMaterial( Material* pMaterial );
	static float ComputeTriangleArea(const D3DXVECTOR3& v1, const D3DXVECTOR3& v2, const D3DXVECTOR3& v3);
	static D3DXVECTOR3 GetColour(float v,float vmin,float vmax);
	static HRESULT SaveNDFImage(ID3D11Device* pd3dDevice, WCHAR* sFileName, unsigned int iWidth, unsigned int iHeight, 
								D3DXVECTOR3* pNormalData, unsigned int iNumNormal, float fNormalizeFactor);
	static bool Save1DPlotData(char* str1DPlotFile, D3DXVECTOR3* pNormalData, unsigned int iNumNormal, bool bWhichAxis);
	static HRESULT SaveFrameBufferToFile( ID3D11DeviceContext *pContext, WCHAR* sFileName,  enum D3DX11_IMAGE_FILE_FORMAT format);
	static HRESULT CreateScreenQuadVB(ID3D11Device* pd3dDevice, ID3D11Buffer** ppQuadVB);
	static float ComputeFresnelTermUsingSchlick(float fRefractiveIndex, const D3DXVECTOR3& vInVec, const D3DXVECTOR3& vHalfVec);
	//debug function
	static void PrintD3DXMatrix(const D3DXMATRIX& pMat);
};

